import com.controller.IndexController;
import com.controller.ProjectController;
import com.demo.HelloController;
import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import com.model.*;
import com.routes.AdminRoutes;
import com.routes.ProjectRoutes;
import com.routes.StudentRoutes;
import com.routes.TeacherRoutes;

/**
 * Created by chaiyuan on 2017/5/3.
 */
public class AppConfig extends JFinalConfig {

    public void configConstant(Constants me) {
        me.setDevMode(true);
        me.setViewType(ViewType.JSP);
        me.setBaseDownloadPath("upload");
    }
    /*
       定義controller
        */
    public void configRoute(Routes me) {
        me.add("/index",IndexController.class);
        me.add(new ProjectRoutes());
        me.add(new StudentRoutes());
        me.add(new TeacherRoutes());
        me.add(new AdminRoutes());

    }

    /*
    公用模板
     */
    public void configEngine(Engine me) {

    }

    /*
    数据库支持activeRecord
     */
    public void configPlugin(Plugins me) {
        C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://127.0.0.1:3306/graduation", "root", "root");
        me.add(cp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        me.add(arp);
        arp.addMapping("user", User.class);
       arp.addMapping("student", "stu_id", Student.class);
       arp.addMapping("teacher", "tea_id", Teacher.class);
       arp.addMapping("project",  Project.class);
        arp.addMapping("user_project", "student_id" ,UserProject.class);
        arp.addMapping("teacher_grade",  TeacherGrade.class);
    }
   /*
    定義攔截器
    */
    public void configInterceptor(Interceptors me) {
    }
    /*
    定義handler
     */
    public void configHandler(Handlers me) {
    }
}
